package com.flong.jsoup.fl;

import java.net.URL;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

public class Htjf {

	
	public static void main(String[] args)throws Exception {
		
		
		
		//http://www.66law.cn/question/htjf/list_2.aspx
		
		StringBuilder buffer =new StringBuilder();
	 	for (int i = 1; i <=100; i++) {
			
			if(i==1){
				String url  = "http://www.66law.cn/question/htjf/";
				Document doc =Jsoup.parse(new URL(url), 30000);
				
				if(doc!=null){
					Elements wt_lists = doc.select("div[class='wt_list']");
					
					for(Element wtList:wt_lists){
						Elements trs = wtList.select("tr:gt(1)");
						for(Element tr:trs){
							String aherf = "http://www.66law.cn"+tr.select("td:eq(0)").select("a:eq(1)").attr("href");
							System.out.println(aherf);
							
							buffer.append(aherf+"\n");
						}
					}
				}
			}else{
				
				String url  = "http://www.66law.cn/question/htjf/list_"+i+".aspx";
				Document doc =Jsoup.parse(new URL(url), 30000);
				
				if(doc!=null){
					Elements wt_lists = doc.select("div[class='wt_list']");
					
					for(Element wtList:wt_lists){
						Elements trs = wtList.select("tr:gt(1)");
						for(Element tr:trs){
							String aherf = "http://www.66law.cn"+tr.select("td:eq(0)").select("a:eq(1)").attr("href");
							buffer.append(aherf+"\n");
						}
					}
				}
				
				
			}
		}
		
	 	String string = buffer.toString();
	
	 	
	 	System.out.println(string);
		
		
		
		
		
 
		
	}
	
}
